<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
       // 1,使用冒泡排序：  [90,65,78,66,48,39,92,73]  使用数组解构
        const numArray = [90,65,78,66,48,39,92,73];
        for(var i =0;i<numArray.length;i++){
            for(var j =0;j<numArray.length-i;j++){
                if(numArray[j]>numArray[j+1]){
                    [numArray[j],numArray[j+1]]=[numArray[j+1],numArray[j]];
                }
            }
        }
        console.log(numArray);
        //2,将数组的单词全转为大写，要求 使用箭头函数
        const countries = ['Finland', 'Sweden', 'Norway', 'Denmark', 'Iceland']
       const newCoutries = countries.map(
            (item)=>item.toUpperCase()//转大写
            
        )
        console.log(newCoutries);
        //编写一个函数来查找字符串数组中的最长公共前缀，如果不存在公共前缀，返回空字符串 ""。
    
        //查找字符串数组长度最短的并返回长度。
        const arrays = ["flower","flow","flowght"]
       
        const getShortest =(array)=>{
            let shortest=0;
          for(var i =0;i<array.length-1;i++){
            shortest =array[i].length<array[i+1].length?array[i].length:array[i+1].length;
          }
          return shortest;
        }
       
       const prefix = (array)=>{

            shortest = getShortest(array);
            
                var pub =" ";
            for(let i =
            0;i<shortest;i++){
                let c=0;
                for(var j =0;j<array.length-1;j++){
                   if(array[j][i]!=array[j+1][i]){
                    break;
                   }else{
                    c++;
                   }
                }
            
                if (c==array.length-1){
                    pub+=array[0][i];
                }
                


            }
            if(pub==" "){
                return null;
            }else{
                return pub;
            }   

       }
       console.log(prefix(arrays));
       
    
    </script>
</body>
</html>